var ShellUtil = function()
{
	this.shell = new ActiveXObject("WScript.Shell");
	this.run = function(provided_commandline)
	{
		this.shell.Run(provided_commandline);
	}
}
var StrUtil = function()
{
	this.replaceall = function(provided_str, provided_findstr, provided_replacestr)
	{
		var pattern = new RegExp(provided_findstr, "g");
		return provided_str.replace(pattern, provided_replacestr);
	}
}
var NameValue = function(provided_namevaluestr)
{
	var templ = provided_namevaluestr.split("=");
	this.name = templ[0];
	this.value = templ[1];
	this.matchname = function(provided_name)
	{
		return (this.name.toUpperCase() == provided_name.toUpperCase());
	}
}
var KeyCollection = function(provided_keystr)
{
	var tempkeylist = new Array();
	tempkeylist.length = 0;
	if(provided_keystr)
	{
		var x = provided_keystr.split("&");
		for(var icnt = 0; icnt < x.length; icnt++)
		{
			tempkeylist[tempkeylist.length] = new NameValue(x[icnt]);
		}
	}
	this.arr = tempkeylist;
	this.findindex = function(provided_name)
	{
		if(this.arr.length != 0)
		{
			for(var icnt = 0; icnt < this.arr.length; icnt++)
			{
				if(this.arr[icnt].matchname(provided_name))
				{
					return icnt;
				}
			}
		}
		return -1;
	}
	this.getvalue = function(provided_name)
	{
		var idx = this.findindex(provided_name);
		if(idx == -1)
		{
			return "";
		}
		else
		{
			return this.arr[idx].value;
		}
	}
}
var MyNetwork = function()
{
	var objnw = new ActiveXObject("WScript.Network");
	this.network = objnw;
	this.username = objnw.UserName;
	this.computername = objnw.ComputerName;
	this.userdomain = objnw.UserDomain;
}
var UrlUtil = function()
{
	this.urltounc = function(provided_url)
	{
		var ret = provided_url.replace("file:", "");
		ret = (new StrUtil()).replaceall(ret, "/", "\\");
		return ret;
	}
	this.unctourl = function(provided_unc)
	{
		var ret = (new StrUtil()).replaceall(provided_unc, "\\\\", "/");
		return ("file:" + ret);
	}
}
var FileUtil = function()
{
	this.fso = new ActiveXObject("Scripting.FileSystemObject");
	this.fileexists = function(provided_path)
	{
		return this.fso.FileExists(provided_path);
	}
	this.createfolder = function(provided_path)
	{
		if(!this.fso.FolderExists(provided_path))
		{
			this.fso.CreateFolder(provided_path);
		}
	}
	this.writefile = function(provided_filename, provided_data)
	{
		var iomode = 2;
		var file = this.fso.OpenTextFile(provided_filename, iomode, true);
		file.Write(provided_data);
		file.Close();
	}
	this.readfile = function(provided_filename)
	{
		var iomode = 1;
		var strdata = "";
		if(this.fso.FileExists(provided_filename))
		{
			var file = this.fso.OpenTextFile(provided_filename, iomode, false);
			while(!file.AtEndOfStream)
			{
				strdata += (file.ReadLine() + "\n");
			}
			file.Close();
		}
		return strdata;
	}
	this.readfileaslines = function(provided_filename)
	{
		var strlines = this.readfile(provided_filename);
		var ret = new Array();
		ret.length = 0;
		if(strlines != "")
		{
			ret = strlines.split("\n");
		}
		return ret;
	}
	this.appendfile = function(provided_filename, provided_line)
	{
		var iomode = 8;
		var file = this.fso.OpenTextFile(provided_filename, iomode, true);
		file.Write(provided_line + "\n");
		file.Close();
	}
	this.getfiles = function(provided_path)
	{
		var ret = new Array();
		ret.length = 0;
		if(this.fso.FolderExists(provided_path))
		{
			var myfolder = this.fso.GetFolder(provided_path);
			var myfiles = new Enumerator(myfolder.Files);
			for(; !myfiles.atEnd(); myfiles.moveNext())
			{
				ret[ret.length] = myfiles.item();
			}
		}
		return ret;
	}
	this.getfolders = function(provided_path)
	{
		var ret = new Array();
		ret.length = 0;
		if(this.fso.FolderExists(provided_path))
		{
			var myfolder = this.fso.GetFolder(provided_path);
			var mysubfolders = new Enumerator(myfolder.SubFolders);
			for(; !mysubfolders.atEnd(); mysubfolders.moveNext())
			{
				ret[ret.length] = mysubfolders.item();
			}
		}
		return ret;
	}
	this.copyfolder = function(provided_source, provided_destination)
	{
		if(this.fso.FolderExists(provided_source))
		{
			this.fso.GetFolder(provided_source).Copy(provided_destination);
		}
	}
	this.copyfile = function(provided_source, provided_destination)
	{
		if(this.fso.FileExists(provided_source))
		{
			this.fso.GetFile(provided_source).Copy(provided_destination);
		}
	}
	this.gettempfolderpath = function()
	{
		var TemporaryFolder = 2;
		var ret = this.fso.GetSpecialFolder(TemporaryFolder);
		return ret.Path;
	}
	this.gettempfilename = function(provided_extension)
	{
		var ret = this.gettempfolderpath();
		ret += "\\";
		ret += this.fso.GetTempName();
		if(provided_extension)
		{
			ret += provided_extension;
		}
		return ret;
	}
}
var DateTimeUtil = function(provided_dtvalue)
{
	var tempdate = new Date();
	if(provided_dtvalue != null)
	{
		var tempdate = new Date(provided_dtvalue);
	}
	this.year = tempdate.getFullYear();
	this.month = tempdate.getMonth() + 1;
	this.day = tempdate.getDate();
	this.yearstr = this.year.toString();
	this.monthstr = "0" + this.month.toString();
	this.monthstr = this.monthstr.substring(this.monthstr.length - 2, this.monthstr.length);
	this.daystr = "0" + this.day.toString();
	this.daystr = this.daystr.substring(this.daystr.length -2, this.daystr.length);
	this.hour = tempdate.getHours();
	this.minute = tempdate.getMinutes();
	this.second = tempdate.getSeconds();
	this.millisecond = tempdate.getMilliseconds();
	this.hourstr = "0" + this.hour.toString();
	this.hourstr = this.hourstr.substring(this.hourstr.length - 2, this.hourstr.length);
	this.minutestr = "0" + this.minute.toString();
	this.minutestr = this.minutestr.substring(this.minutestr.length - 2, this.minutestr.length);
	this.secondstr = "0" + this.second.toString();
	this.secondstr = this.secondstr.substring(this.secondstr.length - 2, this.secondstr.length);
	this.millisecondstr = "00" + this.millisecond.toString();
	this.millisecondstr = this.millisecondstr.substring(this.millisecondstr.length -3, this.millisecondstr.length);
	this.yyyymmdd = this.yearstr + "/" + this.monthstr + "/" + this.daystr;
	this.hhmmss = this.hourstr + ":" + this.minutestr + ":" + this.secondstr;
	this.yyyymmddhhmmss = this.yyyymmdd + " " + this.hhmmss;
	this.gettomorrow = function()
	{
		var d = new Date(this.yyyymmdd);
		return new Date(d.getFullYear(), d.getMonth(), d.getDate() + 1);
	}
	this.getyesterday = function()
	{
		var d = new Date(this.yyyymmdd);
		return new Date(d.getFullYear(), d.getMonth(), d.getDate() - 1);
	}
}
var MyLocation = function()
{
	this.location = location;
	this.keycollection = new KeyCollection(this.location.search.substring(1));
	this.getkeyvalue = function(provided_name)
	{
		return this.keycollection.getvalue(provided_name);
	}
	this.directoryname = this.location.href.substring(0, location.href.lastIndexOf("/") + 1);
	var fn = "";
	if(this.location.href.indexOf("?") == -1)
	{
		fn = this.location.href.substring(location.href.lastIndexOf("/") + 1);
	}
	else
	{
		fn = this.location.href.substring(location.href.lastIndexOf("/") + 1, location.href.indexOf("?"));
	}
	this.filename = fn;
	this.fullname = this.directoryname + this.filename;
	this.filetitle = this.filename.substring(0, this.filename.indexOf("."));
}

function setclipboard(provided_str)
{
	clipboardData.setData("text", provided_str);
}
function debugout(provided_message)
{
	var fn = "c:\\temp\\bgardendebug.txt";
	(new FileUtil()).appendfile(fn, (new DateTimeUtil()).yyyymmddhhmmss + " " + provided_message);
}

function messageout(provided_message, provided_errorlevel, provided_source)
{
	try
	{
		var dtu = new DateTimeUtil();
		var dividstr = "globalmessage" + dtu.yearst + dtu.monthstr + dtu.daystr + dtu.hourstr + dtu.minutestr + dtu.secondstr + dtu.millisecondstr;
		var sourcestr = provided_source;
		if(!sourcestr)
		{
			sourcestr = "not specified";
		}
		sourcestr = "from " + sourcestr;
		var levelstr = "I";
		var fontcolor = "#3cb371";
		switch(provided_errorlevel.toUpperCase())
		{
			case "INFORMATION":
				{
					levelstr = "I";
					fontcolor = "#3cb371";
					break;
				}
			case "WARNING":
				{
					levelstr = "W";
					fontcolor = "#ffa500";
					break;
				}
			case "ERROR":
				{
					levelstr = "E";
					fontcolor = "#ff0000";
					break;
				}
			default:
				{
					break;
				}
		}
		var tdstr = "<td style=\"font-size:12px;text-align:left;color:'";
		tdstr += fontcolor;
		tdstr +="';\"";
		tdstr += " onmouseover=\"this.style.background='#e6e6fa';\"";
		tdstr += " onmouseout=\"this.style.background='#ffffff';\"";
		tdstr += (" onclick=\"var deln = document.getElementById('" + dividstr + "'); var mypare = deln.parentNode; mypare.removeChild(deln);");
		tdstr += "\">";

		var strhtml = "<div id=\"" + dividstr + "\">";
		strhtml += "<table><tr>";
		strhtml += tdstr;
		strhtml += dtu.yyyymmddhhmmss;
		strhtml += "</td>";
		strhtml += tdstr;
		strhtml += levelstr;
		strhtml += "</td>";
		strhtml += tdstr;
		strhtml += provided_message;
		strhtml += "</td>";
		strhtml += tdstr;
		strhtml += sourcestr;
		strhtml += "</td>";
		strhtml += "</tr></table>";
		strhtml += "</div>";

		document.getElementById("globallogarea").innerHTML += strhtml;
		document.getElementById("globallogarea").style.display = "";
	}
	catch(e)
	{
		debugout("messageout error :" + provided_errorlevel + " " + provided_message + " from " + provided_source);
	}
}
